<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="${staticServer}/inc/style/main.css"/>
    <link rel="stylesheet" href="${staticServer}/inc/style/page.css"/>
    <link rel="stylesheet" href="${staticServer}/css/struct_info.css"/>
    <script src="${staticServer}/inc/js/jquery.js"></script>
    <script src="${staticServer}/inc/js/pageset.js"></script>
    <script src="${staticServer}/inc/js/submitter.js"></script>
    <script src="${staticServer}/inc/js/infopad.js?2.2"></script>
    <script type="text/javascript" src="${staticServer}/common/uploadify/jquery.uploadify.js"></script>
    <script type="text/javascript" src="${staticServer}/js/web/uploadImg.js?1.5"></script>

    <link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css"/>
    <script src="${staticServer}/inc/js/datepicker.js"></script>

    <script>
        var contextPath = '${contextPath}';
        var _contextPath = '${staticServer}';

        $(function () {
            $("#type").val("<#if goods??>${goods.type}</#if>");
            $("#item").val("<#if goods??>${goods.id}</#if>");

        });

        function distribution() {
            var region = $("#center").val();
            var center_name = $("#center option:selected").text();
            var goodNameId = $("#item").val();
            var item_name = $("#item option:selected").text();
            var number2 = $("#number2").val();
            var msg = $("#msg").val();
            if (region == "") {
                infopad.err("请选择中心!");
                return false;
            }
            if (item_name == "" || item_name == null) {
                infopad.err("请选择分配物品!");
                return false;
            }
            if (number2 == "") {
                infopad.err("请选择分配数量!");
                return false;
            }

            $.ajax({
                type: 'POST',
                url: 'toDistribution.htm',
                data: {
                    "region": region,
                    "itemName": item_name,
                    "number": number2,
                    "msg": msg,
                    "goodNameId": goodNameId,
                    "center_name": center_name
                },
                dataType: "text",
                success: function (data) {
                    if (data != null && data == "true") {
                        alert("操作成功!");
                        window.location.href = "${contextPath}/goods/goodsList.htm";
                    } else {
                        alert("操作失败!");
                    }
                },
                error: function () {
                    alert("系统出现问题");
                }
            });
        }
    </script>
    <script>
        function getNumber() {
            var id = $("#item").val();
            $.ajax({
                type: 'POST',
                url: 'getGoodsNumber.htm',
                data: {"id": id},
                dataType: "text",
                success: function (data) {
                    if (data != null) {
                        $("#number1").val(data);
                    } else {
                        alert("系统出现问题!");
                    }
                },
                error: function () {
                    alert("系统出现问题");
                }
            });
        }
        function judgeNumber() {
            if (Number($("#number2").val()) <= 0) {
                infopad.err("请输入正确的数量!");
                $("#number2").val("");
            }

            if (Number($("#number2").val()) > Number($("#number1").val())) {
                infopad.err("分配数量不能大于库存数量!");
                $("#number2").val("");
            }

        }
    </script>

</head>
<input type="hidden" id="id" value="<#if goods??>${goods.id}</#if>">
<body>
<div id="home_link">
    <ul>
        <li></li>
        <li>&gt;</li>
        <li>采购管理</li>
        <li>&gt;</li>
        <li class="current">title</li>
    </ul>
</div>

<div id="container">
    <div id="title">物品出入库</div>
    <table id="infotable">
        <tr>
            <th style="color:crimson">分配中心:</th>
            <td>
                <select id="center">
                <#if offList??>
                    <#list offList as offList>
                        <option value="${offList.keyname}">${offList.name}</option>
                    </#list>
                </#if>
                </select>
            </td>
        </tr>
        <tr>
            <th>物品名称:</th>
            <td>
                <select id="item" onchange="getNumber()">
                <#if list??>
                    <#list list as goods>
                        <option value="${goods.id}">${goods.item_name}</option>
                    </#list>
                </#if>
                </select>
            </td>
        </tr>
        <tr>
            <th>库存数量:</th>
            <td>
                <input id="number1" value="${number}" disabled="disabled"/>
            </td>

        </tr>
        <tr>
            <th style="color:crimson">分配数量:</th>
            <td>
                <input id="number2" style="width:150px;" onblur="judgeNumber()" onchange="totalCalculation()"
                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">
            </td>

        </tr>
        <th>备注:</th>
        <td>
            <textarea id="msg" style="width:400px;height: 150px;"></textarea>

        </td>
        </tr>

    </table>
    <div id="controlbar">
        <input type="button" class="submit" onclick="distribution()" value="  分  配  "/>
    </div>
</div>

</body>
</html>